﻿using KwaiXiaoDian.Entity.Common;
using KwaiXiaoDian.Entity.DO;
using KwaiXiaoDian.Entity.VO.Product;
using KwaiXiaoDian.IDao;
using KwaiXiaoDian.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq.Expressions;
using SSharing.Frameworks.NetCore.Common.Extends;

namespace KwaiXiaoDian.Service
{
    public class ChannelService : BaseService<TChannel>, IChannelService
    {
        private readonly IChannelDao _channelDao;

        public ChannelService(IChannelDao channelDao) : base(channelDao)
        {
            _channelDao = channelDao;
        }

        /// <summary>
        /// 获取全部Channel列表
        /// </summary>
        /// <returns></returns>
        public IList<Channel> GetAllChannels()
        {
            IList<Channel> allChannels = new List<Channel>();

            var list = _channelDao.Get(p => p.IsEnabled == Enums.IsEnabledType.Y.ToString());
            if (!list.HasValue())
            {
                return allChannels;
            }

            foreach (var item in list)
            {
                allChannels.Add(new Channel
                {
                    Id = item.Id,
                    ChannelId = item.ChannelId.HasValue ? item.ChannelId.Value.ToString() : "",
                    ChannelName = item.ChannelName,
                    Sort = item.Sort ?? 1
                });
            }

            //排序
            allChannels = allChannels.OrderBy(p => p.Sort).ToList();

            return allChannels;
        }

        /// <summary>
        /// 获取Channel列表依据ChannelId
        /// </summary>
        /// <param name="channelIds"></param>
        /// <returns></returns>
        public IList<TChannel> GetByChannelIds(List<long> channelIds)
        {
            return _channelDao.GetByChannelIds(channelIds);
        }

    }
}
